home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / VCSLID.ZIP / SLIDETST.C < prev    next >
Text File  |  1993-08-16  |  9KB  |  316 lines

  1. /***************************************************************
  2.  
  3.    slidetst.c
  4.  
  5.    Tests the slider control
  6.  
  7.    Author:  Wade Cobb
  8.  
  9.    Date:    August 3, 1993
  10.  
  11. ****************************************************************/
  12. #define  STRICT
  13. #include <windows.h>
  14. #include <stdlib.h>
  15. #include "slider.h"
  16. #include "slidetst.h"
  17.  
  18. //These are globals for convenience only.
  19. HWND        hVertEdit;
  20. HWND        hHorzEdit;
  21. HWND        hWndVert;
  22. HWND        hWndHorz;
  23. HWND        hInfo;
  24. int         nLow,nHigh;
  25. HINSTANCE   hInstMain;
  26. /***************************************************************
  27.  
  28.                   Main Window Procedure
  29.  
  30. ****************************************************************/
  31. int PASCAL WinMain (HINSTANCE hInstance, 
  32.                     HINSTANCE hPrevInstance,
  33.                     LPSTR     lpszCmdLine, 
  34.                     int       nCmdShow)
  35. {
  36.     WNDCLASS    wc;
  37.     HWND        hWnd;
  38.     MSG         msg;
  39.     TEXTMETRIC  tm;
  40.     HDC         hDC;
  41.     WORD        cxFont;
  42.     WORD        cyFont;
  43.  
  44.  
  45.     if (!hPrevInstance)
  46.     {
  47.         wc.style          = CS_HREDRAW | CS_VREDRAW;
  48.         wc.lpfnWndProc    = slidetstWndProc;
  49.         wc.cbClsExtra     = 0;
  50.         wc.cbWndExtra     = 0;
  51.         wc.hInstance      = hInstance;
  52.         wc.hIcon          = LoadIcon(hInstance, "slidetstIcon");
  53.         wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
  54.         wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
  55.         wc.lpszMenuName   = "slidetstMenu";
  56.         wc.lpszClassName  = "slidetst";
  57.  
  58.  
  59.         if (!RegisterClass(&wc))
  60.             return FALSE;
  61.     }
  62.  
  63.     hInstMain=hInstance;
  64.  
  65.     //Create and show main window.
  66.     hWnd=CreateWindow("slidetst", "Slider Test",
  67.                       WS_MINIMIZEBOX | WS_OVERLAPPEDWINDOW,
  68.                       35, 35, 350, 340,
  69.                       NULL, NULL, hInstance, NULL);
  70.  
  71.     ShowWindow(hWnd, nCmdShow);
  72.     UpdateWindow(hWnd);
  73.  
  74.       // Force the slider dll to load
  75.     registerSlider();
  76.  
  77.     //Get text dimensions on which to base control sizes.
  78.     hDC=GetDC(hWnd);
  79.     GetTextMetrics(hDC, &tm);
  80.     cxFont=tm.tmAveCharWidth;
  81.     cyFont=tm.tmHeight;
  82.     ReleaseDC(hWnd, hDC);
  83.  
  84.     hVertEdit=CreateWindow("edit", "50",
  85.                  WS_VISIBLE | WS_CHILD | ES_LEFT | WS_BORDER,
  86.                  2+10*cxFont, 2, 10*cxFont, (cyFont*3)/2,
  87.                  hWnd, (HMENU)ID_VERTEDIT, hInstance, 0L);
  88.  
  89.     SendMessage(hVertEdit, EM_LIMITTEXT, 2, 0L);
  90.  
  91.     /*
  92.      * Width is forced odd with 1+(2*cxFont) so the small triangle
  93.      * looks perfectly centered.  Simple aesthetics.
  94.      *
  95.      * Parent window is default associate.
  96.      */
  97.  
  98.     hWndVert=CreateWindow("slider", "30,6000,35",
  99.                  WS_VISIBLE | WS_CHILD | 
  100.                  SCS_VERTICAL|SCS_TEXTHASRANGE|
  101.                  SCS_RIGHTTICKS|SCS_LEFTTICKS,
  102.                  2+20*cxFont+4, 2, 40, 180,
  103.                  hWnd, (HMENU)ID_VERTSCROLL, hInstance, 0L);
  104.  
  105.     //Create a horizonal edit control with a horizontal slider
  106.     hHorzEdit=CreateWindow("edit", "50",
  107.                  WS_VISIBLE | WS_CHILD | ES_LEFT | WS_BORDER,
  108.                  2, 180, 10*cxFont, (cyFont*3)/2,
  109.                  hWnd, (HMENU)ID_HORZEDIT, hInstance, 0L);
  110.  
  111.     //Parent window is default associate.
  112.     hWndHorz=CreateWindow("slider", "1,32767,50",
  113.                  WS_VISIBLE | WS_CHILD | 
  114.                  SCS_HORIZONTAL|
  115.                  SCS_TEXTHASRANGE|SCS_TOPTICKS|SCS_BOTTOMTICKS,
  116.                  2, 216, 280, 40,
  117.                  hWnd, (HMENU)ID_HORZSCROLL, hInstance, 0L);
  118.  
  119.     hInfo=CreateWindow("static", "",
  120.                  WS_VISIBLE | WS_CHILD,
  121.                  2, 260, 200, 20,
  122.                  hWnd, (HMENU)ID_INFO, hInstance, 0L);
  123.  
  124.  
  125.     while (GetMessage(&msg, NULL, 0, 0))
  126.     {
  127.         TranslateMessage(&msg);
  128.         DispatchMessage(&msg);
  129.     }
  130.  
  131.     return msg.wParam;
  132. }
  133.  
  134.  
  135.  
  136. /*
  137.  * slidetstWndProc
  138.  *
  139.  * Purpose:
  140.  *  Window class procedure.  Standard callback.
  141.  *
  142.  * Parameters:
  143.  *  The standard.  See Section 2.4 Windows SDK Guide to Programming,
  144.  *  page 2-4.
  145.  *
  146.  * Return Value:
  147.  *  See Parameters, above.
  148.  *
  149.  */
  150.  
  151. long FAR PASCAL slidetstWndProc(HWND hWnd, UINT iMessage,
  152.                    WPARAM wParam, LPARAM lParam)
  153. {
  154.     short       wPos;
  155.     char        szNum[200];
  156.     int         nNum;
  157.     LONG        lVal;
  158.     FARPROC     fp;
  159.  
  160.     switch (iMessage)
  161.         {
  162.         case WM_CREATE:
  163.             break;
  164.  
  165.         case WM_DESTROY:
  166.             PostQuitMessage(0);
  167.             break;
  168.  
  169.         case WM_CTLCOLOR:
  170.             if ( (HWND)LOWORD(lParam)==hWndVert ||
  171.                  (HWND)LOWORD(lParam)==hWndHorz)
  172.             {
  173.                SetBkColor((HDC)wParam,RGB(192,192,192));
  174.             }
  175.             break;
  176.  
  177.         case WM_COMMAND:
  178.             switch (wParam)
  179.                 {
  180.                 case IDM_EXIT:
  181.                     PostMessage(hWnd, WM_CLOSE, 0, 0L);
  182.                     break;
  183.  
  184.                 case IDM_ENABLEVERT:
  185.                     EnableWindow(hWndVert,TRUE);
  186.                     break;
  187.  
  188.                 case IDM_DISABLEVERT:
  189.                     EnableWindow(hWndVert,FALSE);
  190.                     break;
  191.  
  192.                 case IDM_ENABLEHORZ:
  193.                     EnableWindow(hWndHorz,TRUE);
  194.                     break;
  195.  
  196.                 case IDM_DISABLEHORZ:
  197.                     EnableWindow(hWndHorz,FALSE);
  198.                     break;
  199.  
  200.                 case IDM_GETRANGEHORZ:
  201.                     lVal=SendMessage(hWndHorz,SCM_GETRANGE,0,0L);
  202.                     wsprintf(szNum,"%d to %d",
  203.                              LOWORD(lVal),HIWORD(lVal));
  204.                     MessageBox(hWnd,szNum,"Horizontal Range",MB_OK);
  205.                     break;
  206.  
  207.                 case IDM_GETRANGEVERT:
  208.                     lVal=SendMessage(hWndVert,SCM_GETRANGE,0,0L);
  209.                     wsprintf(szNum,"%d to %d",
  210.                              LOWORD(lVal),HIWORD(lVal));
  211.                     MessageBox(hWnd,szNum,"Vertical Range",MB_OK);
  212.                     break;
  213.  
  214.                 case IDM_SETRANGEVERT:
  215.                     fp=MakeProcInstance((FARPROC)setRangeDlgProc,hInstMain);     
  216.                     if (DialogBox(hInstMain,"SETRANGE",
  217.                                   hWnd,(DLGPROC)setRangeDlgProc))
  218.                     {
  219.                         SendMessage(hWndVert,SCM_SETRANGE,
  220.                                     0,MAKELONG(nLow,nHigh));
  221.                     }
  222.                     FreeProcInstance(fp);
  223.                     break;
  224.  
  225.                 case IDM_SETRANGEHORZ:
  226.                     fp=MakeProcInstance((FARPROC)setRangeDlgProc,hInstMain);     
  227.                     if (DialogBox(hInstMain,"SETRANGE",
  228.                                   hWnd,(DLGPROC)setRangeDlgProc))
  229.                     {
  230.                         SendMessage(hWndHorz,SCM_SETRANGE,
  231.                                     0,MAKELONG(nLow,nHigh));
  232.                     }
  233.                     FreeProcInstance(fp);
  234.                     break;
  235.  
  236.                 case IDM_SETPOSVERT:
  237.                     GetDlgItemText(hWnd,ID_VERTEDIT,szNum,20);
  238.                     nNum=atoi(szNum);
  239.                     SendMessage(hWndVert,SCM_SETPOS,nNum,0L);
  240.                     break;
  241.  
  242.                 case IDM_SETPOSHORZ:
  243.                     GetDlgItemText(hWnd,ID_HORZEDIT,szNum,20);
  244.                     nNum=atoi(szNum);
  245.                     SendMessage(hWndHorz,SCM_SETPOS,nNum,0L);
  246.                     break;
  247.                 }
  248.             break;
  249.  
  250.         case WM_HSCROLL:
  251.  
  252.               // Update edit control
  253.             wPos=(short)SendMessage(hWndHorz,SCM_GETPOS,0,0L);
  254.             wsprintf(szNum, "%d", wPos);
  255.             SetDlgItemText(hWnd, ID_HORZEDIT, szNum);
  256.             break;
  257.  
  258.  
  259.         case WM_VSCROLL:
  260.  
  261.                   // Update edit control
  262.             wPos=(short)SendMessage(hWndVert,SCM_GETPOS,0,0L);
  263.             wsprintf(szNum, "%d", wPos);
  264.             SetDlgItemText(hWnd, ID_VERTEDIT, szNum);
  265.             break;
  266.  
  267.         default:
  268.             return (DefWindowProc(hWnd, iMessage, wParam,